package ServerStuff;

import java.io.IOException;
import java.net.HttpURLConnection;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.json.JSONException;
import org.json.JSONObject;

import Database.DatabaseConnector;

@WebServlet("/RemoveEmployeeServlet")
public class RemoveEmployeeServlet extends HttpServlet{
	private static final long serialVersionUID = 1L;
	
	
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
		DatabaseConnector dbConnect = new DatabaseConnector();
		HttpServletResponse res = (HttpServletResponse) response;
	
		long empID = Long.parseLong(request.getParameter("employee"));
		boolean deleted = dbConnect.removeEmployee(empID);
		
		JSONObject result = new JSONObject();
		
		try {
			result.put("deleted", deleted);
			res.getWriter().print(result);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		
		res.setStatus(HttpURLConnection.HTTP_ACCEPTED);
	}
}
